/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Tribute")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Tribute.findAll", query = "SELECT t FROM Tribute t"),
    @NamedQuery(name = "Tribute.findByEra", query = "SELECT t FROM Tribute t WHERE t.tributePK.era = :era"),
    @NamedQuery(name = "Tribute.findByResource", query = "SELECT t FROM Tribute t WHERE t.tributePK.resource = :resource"),
    @NamedQuery(name = "Tribute.findByAmount", query = "SELECT t FROM Tribute t WHERE t.amount = :amount")})
public class Tribute implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TributePK tributePK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "amount")
    private int amount;
    @JoinColumn(name = "resource", referencedColumnName = "name", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Resource resource1;
    @JoinColumn(name = "era", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Era era1;

    public Tribute() {
    }

    public Tribute(TributePK tributePK) {
        this.tributePK = tributePK;
    }

    public Tribute(TributePK tributePK, int amount) {
        this.tributePK = tributePK;
        this.amount = amount;
    }

    public Tribute(int era, String resource) {
        this.tributePK = new TributePK(era, resource);
    }

    public TributePK getTributePK() {
        return tributePK;
    }

    public void setTributePK(TributePK tributePK) {
        this.tributePK = tributePK;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public Resource getResource1() {
        return resource1;
    }

    public void setResource1(Resource resource1) {
        this.resource1 = resource1;
    }

    public Era getEra1() {
        return era1;
    }

    public void setEra1(Era era1) {
        this.era1 = era1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (tributePK != null ? tributePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Tribute)) {
            return false;
        }
        Tribute other = (Tribute) object;
        if ((this.tributePK == null && other.tributePK != null) || (this.tributePK != null && !this.tributePK.equals(other.tributePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Tribute[ tributePK=" + tributePK + " ]";
    }
    
}
